# Replication archive for: Coppock, Alexander and Seth J. Hill and Lynn Vavreck. 2020. "The Small Effects of Political Advertising are Small Regardless of Context, Message, Sender, or Receiver: Evidence from 59 Real-time Randomized Experiments" Science Advances, forthcoming.

library(tidyverse)
library(estimatr)
library(rmeta)
library(xtable)
source("helpers.R")

favorability_sates <- read_rds("favorability_sates.rds")
vote_choice_sates <- read_rds("vote_choice_sates.rds")
favorability_cates <- read_rds("favorability_cates.rds")
vote_choice_cates <- read_rds("vote_choice_cates.rds")


meta_df <-
  bind_rows(
    sates = favorability_sates,
    sates = vote_choice_sates,
    cates = favorability_cates,
    cates = vote_choice_cates,
    .id = "estimand"
  ) %>%
  mutate(
    dv = if_else(grepl("favor", outcome), "Favorability", "Vote Choice")
  )

tests_df <-
  meta_df %>%
  group_by(estimand, dv) %>%
  do(with(., glance(
    meta.summaries(estimate, std.error, method = "random")
  ))) 


estimates_df <-
  meta_df %>%
  group_by(estimand, dv) %>%
  do(with(., tidy(
    meta.summaries(estimate, std.error, method = "random")
  ))) %>%
  transmute(estimand,
            dv,
            estimate = make_se_entry(estimate, se = std.error, digits = 4))

table_df <-
  left_join(estimates_df, tests_df) %>%
  arrange(rev(estimand), dv)


table_df %>%
  xtable(digits = 4) %>%
  print.xtable(
    include.rownames = FALSE,
    include.colnames = FALSE,
    only.contents = TRUE,
    hline.after = c()
  )
